package com.party.core.service.competition.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.competition.CompetitionGroupResultReadDao;
import com.party.core.dao.write.competition.CompetitionGroupResultWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.competition.CompetitionGroupResult;
import com.party.core.service.competition.ICompetitionGroupResultService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 参赛人员成绩
 *
 * @author Administrator
 */
@Service
public class CompetitionGroupResultService implements ICompetitionGroupResultService {

    @Autowired
    private CompetitionGroupResultReadDao competitionResultReadDao;

    @Autowired
    private CompetitionGroupResultWriteDao competitionResultWriteDao;

    @Override
    public String insert(CompetitionGroupResult t) {
        BaseModel.preInsert(t);
        boolean result = competitionResultWriteDao.insert(t);
        if (result) {
            return t.getId();
        }
        return null;
    }

    @Override
    public boolean update(CompetitionGroupResult t) {
        t.setUpdateDate(new Date());
        return competitionResultWriteDao.update(t);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return competitionResultWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return competitionResultWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return competitionResultWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return competitionResultWriteDao.batchDelete(ids);
    }

    @Override
    public CompetitionGroupResult get(String id) {
        return competitionResultReadDao.get(id);
    }

    @Override
    public List<CompetitionGroupResult> listPage(CompetitionGroupResult t, Page page) {
        return competitionResultReadDao.listPage(t, page);
    }

    @Override
    public List<CompetitionGroupResult> list(CompetitionGroupResult t) {
        return competitionResultReadDao.listPage(t, null);
    }

    @Override
    public List<CompetitionGroupResult> batchList(Set<String> ids, CompetitionGroupResult t, Page page) {
        if (CollectionUtils.isEmpty(ids)) {
            return Collections.EMPTY_LIST;
        }
        return competitionResultReadDao.batchList(ids, new HashedMap(), page);
    }

    @Override
    public List<Map<String, Object>> getByGroup(Map<String, Object> params, Page page) {
        return competitionResultReadDao.getByGroup(params, page);
    }

    @Override
    public CompetitionGroupResult getUnique(CompetitionGroupResult query) {
        return competitionResultReadDao.getUnique(query);
    }

    @Override
    public void deleteByUnique(CompetitionGroupResult query) {
        competitionResultWriteDao.deleteByUnique(query);
    }

    @Override
    public void deleteByProjectId(String projectId) {
        competitionResultWriteDao.deleteByProjectId(projectId);
    }
}
